﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using CnyeCPlus.ExtSurface;
using Windows.UI;
// The Grouped Items Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234231

namespace CnyeCPlusTest
{
    /// <summary>
    /// A page that displays a grouped collection of items.
    /// </summary>
    public sealed partial class GroupedItemsPage : CnyeCPlusTest.Common.LayoutAwarePage
    {
        public GroupedItemsPage()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {

            //this.DefaultViewModel["Groups"] = sampleDataGroups;

        }

        /// <summary>
        /// Invoked when a group header is clicked.
        /// </summary>
        /// <param name="sender">The Button used as a group header for the selected group.</param>
        /// <param name="e">Event data that describes how the click was initiated.</param>
        void Header_Click(object sender, RoutedEventArgs e)
        {
            //Class1 c = new Class1();
            //System.Diagnostics.Debug.WriteLine("val:" + c.gval());
            ESurfaceImageSource Scenario1Drawing = new ESurfaceImageSource((int)Img.Width, (int)Img.Height, true);
            this.Img.Source = Scenario1Drawing;
            // Begin updating the SurfaceImageSource
            Scenario1Drawing.BeginDraw();

            // Clear background
            Scenario1Drawing.Clear(Colors.White);

            // Create a new pseudo-random number generator
            //Random randomGenerator = new Random();
            //byte[] pixelValues = new byte[3]; // Represents the red, green, and blue channels of a color

            //// Draw 50 random retangles
            //for (int i = 0; i < 50; i++)
            //{
            //    // Generate a new random color
            //    randomGenerator.NextBytes(pixelValues);
            //    Color color = new Color() { R = pixelValues[0], G = pixelValues[1], B = pixelValues[2], A = 255 };

            //    // Add a new randomly colored 50x50 rectangle that will fit somewhere within the bounds of the Image1 control
            //    Scenario1Drawing.FillSolidRect(
            //        color,
            //        new Rect(randomGenerator.Next((int)Img.Width - 50), randomGenerator.Next((int)Img.Height - 50), 50, 50)
            //        );
            //}
            Scenario1Drawing.CreateTextFormat("微软雅黑", 30);
            Scenario1Drawing.DrawText("aaaaaaa", Colors.Black, new Rect(0, 0, 200, 300));
            Scenario1Drawing.FreeTextFormat();
            Scenario1Drawing.DrawRect(Colors.Black, new Rect(1, 1, 50, 50));
            Scenario1Drawing.DrawRect(Colors.Black, new Rect(55, 55, 50, 50), true);
            //Scenario1Drawing.DrawText("aaaaaaa", Colors.Black, new Rect(0, 0, 200, 300));
            //Scenario1Drawing.DrawText();
            // Stop updating the SurfaceImageSource and draw its contents
            Scenario1Drawing.EndDraw();
        }

        /// <summary>
        /// Invoked when an item within a group is clicked.
        /// </summary>
        /// <param name="sender">The GridView (or ListView when the application is snapped)
        /// displaying the item clicked.</param>
        /// <param name="e">Event data that describes the item clicked.</param>
        void ItemView_ItemClick(object sender, ItemClickEventArgs e)
        {

        }
    }
}
